//
//  MySaveViewController.m
//  ForengnMenu
//
//  Created by @-@ on 16/1/14.
//  Copyright © 2016年 余旺. All rights reserved.
//

#import "MySaveViewController.h"
#import "MySaveTableViewCell.h"
#import "MenuContentViewController.h"

@interface MySaveViewController ()

@property NSArray * recipeArray;

@property NSMutableArray * muArray;

@property (weak, nonatomic) IBOutlet UITableView *myTableView;

@end

@implementation MySaveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _muArray = [NSMutableArray new];
    
    if (_isOk) {
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"Icon_return"] forState:UIControlStateNormal];
        button.frame = CGRectMake(0, 0, 50, 30);
        [button addTarget:self action:@selector(returnAction) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        [_muArray addObject:@""];
    }else{
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"headImage.jpg"] forState:UIControlStateNormal];
        button.frame = CGRectMake(0, 0, 30, 30);
        button.layer.cornerRadius = button.frame.size.height/2.0f;
        button.layer.masksToBounds = YES;
        
        [button addTarget:self action:@selector(headAction) forControlEvents:UIControlEventTouchUpInside];
        
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    }
    
    self.myTableView.backgroundColor =[UIColor colorWithRed:246/255.0f green:247/255.0f blue:239/255.0f alpha:1.0f];
    
    self.myTableView.separatorStyle = UITableViewCellStyleDefault;
    
    //指定的位置
    NSString * RecipeModel = [[NSBundle mainBundle] pathForResource:@"RecipeModel" ofType:@"plist"];
    //大数组
    NSArray * array = [NSArray arrayWithContentsOfFile:RecipeModel];
    
    self.recipeArray = array[0];
    
}
-(void)returnAction{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.recipeArray.count + self.muArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * identifier = @"Cell";
    
    MySaveTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    NSDictionary * array = self.recipeArray[indexPath.section];
    
    NSDictionary * dicArr = array[@"Content"];
    
    cell.foodImageView.image = [UIImage imageNamed:dicArr[@"CookingImage"]];
    
    cell.myTextLabel.text = dicArr[@"RecipeShow"];
    
    cell.diffcultLabel.text = dicArr[@"CookingDifficulty"];
    
    cell.timeLabel.text = dicArr[@"CookingTime"];
    
    cell.backgroundColor = [UIColor clearColor];
    
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 14;
    }else{
        return 12;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary * array = self.recipeArray[indexPath.section];
    
    UIStoryboard * stroyboard = [UIStoryboard storyboardWithName:@"LearnCook" bundle:[NSBundle mainBundle]];
    
    MenuContentViewController * viewController = [stroyboard instantiateViewControllerWithIdentifier:@"MenuController"];
    viewController.recipeArray = array;
    viewController.iskai = YES;
    
    [self.navigationController pushViewController:viewController animated:YES];
    
    
}

- (void)headAction{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"pushSlideslip" object:nil];
    
}


@end
